const express = require('express')
const app = express()
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.use(express.static('./')) // 使用静态资源

const settings = require('./config/settings')
const router = require('./src/routers')

app.use('/', router)
app.use('/api/users', require('./src/routers/users'))
app.use('/api/business', require('./src/routers/business'))
app.use('/api/package', require('./src/routers/package'))
app.use('/api/system', require('./src/routers/system'))
app.use('/api/warrant', require('./src/routers/warrant'))
app.use('/api/finance', require('./src/routers/finance'))
app.use('/api/resources', require('./src/routers/resources'))
app.use('/api/statistics', require('./src/routers/statistics'))
app.use('/api/archives', require('./src/routers/archives'))
app.use('/api/screen', require('./src/routers/screen'))

app.use((err, req, res, next) => {
    console.error(err.stack, 'lalalalla')
    res.status(err.status || 500).send('Something broke!')
})

app.listen(settings.port)